package com.bus.admin.serviceImpl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.bus.admin.controller.helper.$;
import com.bus.admin.bean.Orderbus;
import com.bus.admin.mapper.OrderbusMapper;
import com.bus.admin.service.OrderbusService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bus.admin.bean.result.ResultPage;
import com.bus.admin.controller.model.ApiResultModel;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张子艺
 * @since 2020-04-01
 */
@Service
public class OrderbusServiceImpl extends ServiceImpl<OrderbusMapper, Orderbus> implements OrderbusService {
    /** 添加Orderbus
     * @param orderbus  前端传进的参数
     * @return 返回统一信息
     */
    @Override
    public ApiResultModel addOrderbus(Orderbus orderbus  ) {
           if(this.save(orderbus )){
               return $.success();
           }else{
                return $.error("添加失败");
           }
    }
    /** 编辑跳转页面的回显数据Orderbus
     * @param id  前端传进的参数
     * @return 返回实体类
     */
    @Override
    public Orderbus selectOrderbusByIdOrderbus(Integer id ){
            return this.getById(id);
    }


    /** 编辑Orderbus
     * @param orderbus  前端传进的参数
     * @return 返回统一信息
     */
    @Override
    public ApiResultModel editOrderbus(Orderbus orderbus  ) {
           if(this.updateById(orderbus )){
               return $.success();
           }else{
                return $.error("编辑失败");
           }
    }
    /** 删除一条Orderbus
     * @param id  前端传进的ID
     * @return 返回统一信息
     */
    @Override
    public   ApiResultModel delOrderbus( Integer id  ){
           if(this.removeById(id)){
               return $.success();
           }else{
                return $.error("删除失败");
           }
    }

   /** 分页查询Orderbus
     * @param page  页码
     * @param limit  查几条
     * @param orderbus  前端传进的参数
     * @return 返回统一分页信息
     */
    @Override
    public  ResultPage findOrderbusByPage(Integer page, Integer limit,Orderbus orderbus){
        if(!StrUtil.isBlank(orderbus.getOrdertimeStatTime())){
            orderbus.setOrdertimeStatTime(DateUtil.parseDateTime(orderbus.getOrdertimeStatTime()).getTime()+"");
        }
        if(!StrUtil.isBlank(orderbus.getOrdertimeEndTime())){
            orderbus.setOrdertimeEndTime(DateUtil.parseDateTime(orderbus.getOrdertimeEndTime()).getTime()+"");
        }
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page", (page - 1) * limit);
        paramMap.put("limit", limit);
        paramMap.put("orderbus", orderbus);
        List<Orderbus> list = baseMapper.selectMyPage(paramMap);
        Integer count = baseMapper.countMyPage(paramMap);
        ResultPage<Orderbus> resultPage = new ResultPage<>();
        resultPage.setCode(0);
        resultPage.setCount(count);
        resultPage.setMsg("成功");
        resultPage.setData(list);
        return resultPage;
    }

    @Override
    public List<Integer> find7DayOrder() {
        return baseMapper.find7DayOrder();
    }
}
